Skip to content

Show the questionnaire's conditional flow in a Flow panel - #16

Draft
PSchmiedmayer wants to merge 2 commits into
anvil-authoring-correctnessfrom
feature/branching-graph
Draft

PSchmiedmayer wants to merge 2 commits into
anvil-authoring-correctnessfrom
feature/branching-graph

Conversation

@PSchmiedmayer

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

Authors set enableWhen conditions one item at a time in the inspector.
Nothing shows how the conditions of a whole questionnaire fit together: which questions decide which items, whether a condition refers to a question that comes later, or whether an item can be shown at all.
Validation reports a condition on a missing linkId, but an item that depends on that item, a cycle of conditions, or a group that depends on one of its own children goes unnoticed until someone tries the preview with the right answers.

⚙️ Release Notes

The side panel has a new Flow tab, opened from the toolbar next to Preview and JSON.
It lists every item in document order, indented like the outline, with its conditions below it, and draws an edge from each referenced question to the condition.
Conditions read as when smoke = Yes (yes) followed by and or or for further conditions, depending on enableBehavior.
Coded answers use the display of the referenced question's answer option.

Findings show on the rows and edges:

  • A condition on a linkId that no item has gets a short error stub instead of an edge and the note "No item has this linkId".
  • A condition on a later item has a dashed edge and the note "Refers to a later item".
  • Existing validation findings on a condition, such as a reference to a group or an answer type the question cannot have, give the edge its color and are listed after the condition.
  • An item that no answers can ever enable is marked "Never shown".
  • A summary at the top counts items, conditions and these findings.

Selection is shared with the outline and the inspector.
Clicking an item row selects the item, clicking a condition row selects the item that has the condition, and clicking the question of a condition selects that question.
The edges of the selected item are drawn in the accent color.

The layout is computed in anvil-core by layoutFlow(document), a pure function, and anvil-react renders it with fixed row heights and one SVG for the edges:

const { rows, edges, lanes } = layoutFlow(store.getState().document);
// rows: item rows (depth, behavior, reachable, dependents) and condition rows (question, operator, answer, status)
// edges: { from, to, lane, sourceUid, targetUid, index, status }

The layout keeps document order, because the order is what authors need to judge, and a layered graph layout would reorder items to reduce crossings.
Edges run in lanes to the left of the rows, which is the layout of an arc diagram.
Lanes are assigned greedily with the shortest edges innermost, so edges that share rows never overlap, and edges leaving one question in the same direction can share a lane.
This needs no layout library.

Reachability starts from the items the preview enables with the initial answers and adds every item whose parent can be enabled and whose conditions can hold, until nothing changes.
Whether one condition can hold follows the preview's evaluateCondition: an unanswered question only satisfies exists with false, a comparison with an answer type the question cannot have only satisfies !=, and ordering operators need an ordered answer type.
Any enabled question with the referenced linkId can answer, as in the preview, which keeps answers by linkId.
Cycles without initial answers and conditions on an item's own descendants therefore come out as never shown, and so does everything inside a group that is never shown.
Conditions that can each hold but contradict each other, such as q = 1 and q = 2 with all, are not detected; the README says so.

The rows form an ARIA tree that is the textual equivalent of the graph, and the SVG is hidden from assistive technology.
Item rows are level 1 and deeper by nesting, conditions are one level below their item, and the summary is the tree's description.
Each row has an explicit label, such as "Choice, Do you smoke?, linkId smoke, 4 conditions depend on it" or "when contact is answered, Refers to a later item".
↑ and ↓ move through the rows, Home and End go to the first and last row, ← goes to the item or group a row belongs to, → goes into it, and Enter on a condition moves to the question it refers to.

The panel tolerates imported values of the wrong type, such as a numeric text or an answerCoding that is not an object.
For the same reason, the preview's isItemEnabled and initialAnswers now skip enableWhen, answerOption and initial values that are not arrays, and conditions and answer options that are not objects, since the flow reuses them.

The flow follows the system light or dark appearance like the rest of the editor.

The Flow panel in light mode with "Do you smoke?" selected

The Flow panel in dark mode

The Flow panel at phone width in light mode

The Flow panel at phone width in dark mode

📚 Documentation

The anvil-core README describes layoutFlow and its rows, edges, statuses and reachability.
The anvil-react README lists the built-in side panel tabs and their ids and describes the Flow tab; its host panel example no longer uses a branching graph.
The root README lists the flow view among the features.

✅ Testing

  • anvil-core/test/flow.test.ts covers row order and nesting depth in groups, conditions with all and any, answer formatting with option displays, the missing, later, self and not-a-question statuses, reachability with missing questions, chains, exists false, wrong answer types and ordering operators, groups, cycles and conditions on an item's own children, cycles that initial answers enable, repeated linkIds, lane assignment without overlaps and with shared trunks, and imported values of the wrong type.
  • anvil-react/test/flowPanel.test.tsx covers the tree's row labels, levels and description, edges with validation and later-item findings and the stub for a missing item, visible findings next to a status, imported values of the wrong type, selection from rows, from condition questions and from the store, keyboard navigation including Enter to the referenced question, updates after edits and an empty questionnaire, and checks that React logs no errors, which includes key warnings.

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

The side panel gets a Flow tab that lists every item in document order
with its enableWhen conditions and draws an edge from each referenced
question to the condition. It marks conditions on missing or later
items, reflects validation findings on edges, and marks items that no
answers can enable. Rows form an accessible tree that shares the
selection with the outline and the inspector.

The layout, including lane assignment and reachability, is computed by
layoutFlow in anvil-core. The preview's enablement helpers now skip
imported values that are not arrays or objects, which the layout reuses.
@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant